<?php
namespace app\common\service;

class Dynamic{

    public function __construct(){
    }

    public static function Price(string $stockCode = '' , string $jys = '', array $arr = [])
    {
        $result = ['price'=>'0.00', 'pe'=>'0.00', 'pb'=>'0.00', 'ps'=>'0.00'];
        $stockPrice = null;
        $stockPrice = file_get_contents('https://sqt.gtimg.cn//?q='.strtolower($jys).$stockCode.'&fmt=json&app=wzq&t=');
        if(!empty($stockPrice)){
            preg_match('/\[(.*?)\]/', $stockPrice, $matches);
            if(!empty($matches[1])){
                
                $matches = explode(',', $matches[1]);

                $result['price'] = (float)str_replace('"', '', $matches[3]);
                $result['pe'] = (float)str_replace('"', '',$matches[39]);
                $result['pb'] = (float)str_replace('"', '',$matches[46]);
                $result['ps'] = '0.00';
            }
        }
        return $result;
    }
}